<template>
  <div ref="modal" class="modal-column" @click.stop="void(0)">
    <div class="flex-1 p-16px">
      <Form ref="form"  :labelWidth="110" :model="form" :rules="{}">
        <FormItem :label="category.name+'编码'" prop="code" required>
          <NumberInput v-model.number="form.code" placeholder="请输入编码" @keyup.enter="submit(false)"/>
        </FormItem>
        <FormItem :label="category.name+'名称'" prop="name" required>
          <Input ref="nameRef" type="text" v-model="form.name" placeholder="请输入名称" @keyup.enter="submit(false)"/>
        </FormItem>
<!--        <FormItem label="备注" prop="remark" single>-->
<!--          <Input v-model="form.remark" @keyup.enter="submit(false)"/>-->
<!--        </FormItem>-->
      </Form>
    </div>
    <div class="modal-column-btn modal-column-between">
      <vxe-button @click="$emit('close')">取消</vxe-button>
      <div>
        <vxe-button @click="submit(true)" :loading="loading">保存并结束</vxe-button>
        <vxe-button status="primary" @click="submit(false)" :loading="loading">保存并新增(Enter)</vxe-button>
      </div>
    </div>
  </div>
</template>

<script>/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2022纷析云（杭州）科技有限公司All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : </li>
 * <li>Version     : 1.0</li>
 * <li>Creation    : 2022年10月29日</li>
 * <li>@author     : ____′↘夏悸</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
import {isNumber} from "xe-utils";
import {message} from "heyui.ext";

export default {
  name: "VTableAuxiliaryFastForm",
  props: {
    category: Object,
  },
  data() {
    return {
      loading: false,
      form: {
        code: null,
        name: null,
        remark: null,
        enable: true
      }
    }
  },
  methods: {
    submit(close = false) {
      // let validResult = this.$refs.form.valid();
      // if (validResult.result) {
      //   this.loading = true;
      //   Setting.accountingCategoryDetails.saveAd(Object.assign({
      //     categoryId: this.category.id,
      //     categoryType: this.category.categoryType,
      //   }, this.form)).then(() => {
      //     message.success('添加成功');
      //     if (close) {
      //       this.$emit('success');
      //     } else {
      //       if (isNumber(Number(this.form.code))) {
      //         this.form.code = Number(this.form.code) + 1;
      //       } else {
      //         this.form.code = null;
      //       }
      //       this.form.name = null;
      //       this.form.remark = null;
      //       this.$refs.nameRef.$el.focus();
      //     }
      //   }).finally(() => {
      //     this.loading = false;
      //   })
      // }
    }
  }
}
</script>
